package com.woniuxy.ssm.controller;

import com.woniuxy.ssm.bean.Dept;
import com.woniuxy.ssm.bean.User;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * @author linke
 * @version 1.0
 * @className: UserController
 * @description: Users 控制器
 * @date 2021/11/18 11:40
 *
 * 测试对象类型参数传递
 */
@Controller
@RequestMapping("users")
public class UsersController {

    /**
     * 封装对象接收
     * @param user
     * @return
     */
    @PostMapping ("/add")
    public ModelAndView Users(@RequestBody User user){
        ModelAndView modelAndView = new ModelAndView();
        //接收到的数据 User(uname=3edd, pwd=22, email=ly55421@163.com, ids=[1, 2])
        modelAndView.addObject("users","传入的对象集合数组是:"+user);
        modelAndView.setViewName("usersView");
        return modelAndView;
    }
    /**
     * 指定单一对象接收
     *
     * @param dept
     * @return
     */
    @PostMapping ("/addOne")
    public ModelAndView addOne(Dept dept){
        ModelAndView modelAndView = new ModelAndView();
        //接收到的数据 Dept(deptName=222, deptUser=User(uname=222, pwd=22222, email=222@222, ids=[1, 2]), userList=null)
        modelAndView.addObject("dept","传入的对象集合数组是:"+dept);
        modelAndView.setViewName("deptView");
        return modelAndView;
    }
    /**
     * 指定单一对象接收
     * 多对象传递
     *
     * @param dept
     * @return
     */
    @PostMapping ("/addList")
    public ModelAndView addList(Dept dept){
        ModelAndView modelAndView = new ModelAndView();
        //接收到的数据Dept(deptName=222, deptUser=User(uname=222, pwd=222, email=2222@223,
        // ids=[1, 2]), userList=[User(uname=222, pwd=222, email=2442@333, ids=[2, 3]), User(uname=222, pwd=222, email=22@222, ids=[1, 2])])
        modelAndView.addObject("dept","传入的对象集合数组是:"+dept);
        modelAndView.setViewName("deptView");
        return modelAndView;
    }
}
